package com.cali.libcore.http.interceptor

import okhttp3.Interceptor
import okhttp3.Response

/**
 * @Author HaoXin
 * @Date 2020/11/22
 */
class DownloadInterceptor(private val action: (Long) -> Unit):Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val response = chain.proceed(chain.request())
        val body = response.body()
        return if (body != null) {
            response.newBuilder().body(DownloadResponseBody(body, action)).build()
        } else {
            response
        }
    }
}